﻿Public Class frmBackCare
    Private m_BackCon As New CAermod.BackCon
    Property BackCon() As CAermod.BackCon
        Get
            Return Me.m_BackCon
        End Get
        Set(ByVal value As CAermod.BackCon)
            Me.m_BackCon = value
        End Set
    End Property
    Private Sub frmBackCare_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.EFlex.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        EFlex.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        EFlex.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
        EFlex.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        EFlex.Rows.Count = 0
        EFlex.Cols.Count = 0
        Me.ListBox1.Items.Clear()
        For i As Integer = 0 To Me.m_BackCon.PollutBackCon.Count - 1
            Me.ListBox1.Items.Add(Me.m_BackCon.PollutBackCon.Item(i).Name)
        Next
        If Me.ListBox1.Items.Count > 0 Then
            Me.ListBox1.SelectedIndex = 0
        End If

    End Sub
    ''' <summary>
    ''' 显示数据
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ShowData()
        Dim IndexPollute As Integer = Me.ListBox1.SelectedIndex
        If IndexPollute >= 0 Then
            If Me.m_BackCon.PollutBackCon.Count > 0 AndAlso Me.m_BackCon.PollutBackCon.Item(0).ArrayAverageTimeBackCon(0).ListCareBackCon.Count > 0 Then
                Me.EFlex.Cols.Count = Me.m_BackCon.PollutBackCon.Item(0).ArrayAverageTimeBackCon(0).ListCareBackCon.Count + 2
            Else
                Exit Sub
            End If
            Me.EFlex.Rows.Count = 11

            Me.EFlex.SetData(0, 0, "平均时间")
            Me.EFlex.SetData(1, 0, "1小时")
            Me.EFlex.SetData(2, 0, "2小时")
            Me.EFlex.SetData(3, 0, "3小时")
            Me.EFlex.SetData(4, 0, "4小时")
            Me.EFlex.SetData(5, 0, "6小时")
            Me.EFlex.SetData(6, 0, "8小时")
            Me.EFlex.SetData(7, 0, "12小时")
            Me.EFlex.SetData(8, 0, "24小时")
            Me.EFlex.SetData(9, 0, "月")
            Me.EFlex.SetData(10, 0, "年")

            For i As Integer = 0 To Me.m_BackCon.PollutBackCon.Item(IndexPollute).ArrayAverageTimeBackCon.Length - 1
                For j As Integer = 0 To Me.m_BackCon.PollutBackCon.Item(IndexPollute).ArrayAverageTimeBackCon(i).ListCareBackCon.Count - 1
                    Me.EFlex.SetData(0, j + 1, Me.m_BackCon.PollutBackCon.Item(IndexPollute).ArrayAverageTimeBackCon(i).ListCareBackCon(j).Name)
                    Me.EFlex.SetData(i + 1, j + 1, Me.m_BackCon.PollutBackCon.Item(IndexPollute).ArrayAverageTimeBackCon(i).ListCareBackCon(j).Con)

                Next
                Me.EFlex.SetData(0, Me.m_BackCon.PollutBackCon.Item(IndexPollute).ArrayAverageTimeBackCon(i).ListCareBackCon.Count + 1, "平均值")
                Me.EFlex.SetData(i + 1, Me.m_BackCon.PollutBackCon.Item(IndexPollute).ArrayAverageTimeBackCon(i).ListCareBackCon.Count + 1, Me.m_BackCon.PollutBackCon.Item(IndexPollute).ArrayAverageTimeBackCon(i).AervaggeCon)
             Next
        End If
        Me.EFlex.AutoSizeCols()
    End Sub
    ''' <summary>
    ''' 更新数据
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub UpdateData()
        Dim IndexPollute As Integer = Me.ListBox1.SelectedIndex
        If IndexPollute >= 0 Then
            If Me.m_BackCon.PollutBackCon.Count > 0 AndAlso Me.m_BackCon.PollutBackCon.Item(0).ArrayAverageTimeBackCon(0).ListCareBackCon.Count > 0 Then
                For i As Integer = 0 To Me.m_BackCon.PollutBackCon.Item(IndexPollute).ArrayAverageTimeBackCon.Length - 1
                    For j As Integer = 0 To Me.m_BackCon.PollutBackCon.Item(IndexPollute).ArrayAverageTimeBackCon(i).ListCareBackCon.Count - 1
                        Me.m_BackCon.PollutBackCon.Item(IndexPollute).ArrayAverageTimeBackCon(i).ListCareBackCon(j).Con = Me.EFlex.GetData(i + 1, j + 1)
                    Next
                    Me.m_BackCon.PollutBackCon.Item(IndexPollute).ArrayAverageTimeBackCon(i).AervaggeCon = Me.EFlex.GetData(i + 1, Me.EFlex.Cols.Count - 1)
                Next
            Else
                Exit Sub
            End If
        End If
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        If Me.ListBox1.SelectedIndex >= 0 Then
            ShowData()
        End If
    End Sub

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Me.DialogResult = Windows.Forms.DialogResult.OK

    End Sub

    Private Sub EFlex_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles EFlex.Validating
        UpdateData()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For i As Integer = 0 To Me.EFlex.Rows.Count - 2
            Dim All As Double = 0
            Dim Cout As Integer = 0
            For j As Integer = 0 To Me.EFlex.Cols.Count - 3
                If Me.EFlex.GetData(i + 1, j + 1) >= 0 Then
                    All += Me.EFlex.GetData(i + 1, j + 1)
                    Cout += 1
                End If
            Next
            If Cout > 0 Then
                Dim Aver As Double = All / Cout
                Me.EFlex.SetData(i + 1, Me.EFlex.Cols.Count - 1, Aver)
            End If
        Next
        Me.EFlex.AutoSizeCols()
        UpdateData()
    End Sub
End Class